const { Question } = require('../utils/db')

const writeQuestion = async (username,
                            title,
                            avatar,
                            content,
                            time_limit,
                            memory_limit,
                       cases,) => {
    const publish_date = Date.now()
    const ques = await find()
    const id = ques.length + 1
    const question = new Question({
        username,
        id,
        title,
        avatar,
        content,
        time_limit,
        memory_limit,
        cases,
        publish_date,
    })
    return question.save()
}

const findOne = (id) => {
    return Question.findOne({'_id': id})
}

const find = () => {
    return Question.find()
}

module.exports = {
    writeQuestion,
    findOne,
    find,
}